<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>登录</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
	  <link href="css/style.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="container">
		<div class="col-md-4 location">
	      <div class="form-signin text-center">
	        <h2 class="form-signin-heading">请登录</h2>
	        <label for="inputUserName" class="sr-only">用户名</label>
	        <input type="email" id="inputUserName" class="form-control s-margin-2" placeholder="用户名" required autofocus>
	        <label for="inputPassword" class="sr-only">密码</label>
	        <input type="password" id="inputPassword" class="form-control s-margin-1" placeholder="密码" required>
	        <button class="btn btn-lg btn-primary btn-block s-margin-2" onclick="userLogin()">登录</button>
			  <button class="btn btn-lg btn-default btn-block s-margin-2" onclick="toRegister()">注册</button>
	      </div>
	      </div>
	</div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
	<script src="js/util.js"></script>
  	<script type="application/javascript">
		function userLogin() {
		    var user = {};
		    user.userName = document.getElementById("inputUserName").value;
		    user.userPassword = document.getElementById("inputPassword").value;
		    var response;
            $.ajax({
                async : false,
                type : 'POST',
                url : address+"userLogin",
                data : user,
                dataType : 'json',
                success : function(result) {
                    response = result;
                },
                error : function(result) {
                    alert('服务器异常');
                }
            });
			if(response.status == "0"){
			    setCookie("user",response.content,1);
			    window.location.href=address+"words.html";
			}
			else{
			    alert(response.content);
			}
        }

        function toRegister() {
			window.location.href = address+"register.html";
        }
	</script>
  </body>
</html>